#include <iostream>
using namespace std;

#include "inverse.h"
#include "vectorTestCase.h"
#include "../libpresenter/presenter.h"

//
// Test Vectors
//
unsigned char p1[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char k1[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
		  	0x00};
unsigned char c1[8] = {0x55, 0x79, 0xC1, 0x38, 0x7B, 0x22, 0x84, 0x45};

unsigned char p2[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char k2[10] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
		       	0xFF};
unsigned char c2[8] = {0xE7, 0x2C, 0x46, 0xC0, 0xF5, 0x94, 0x50, 0x49};

unsigned char p3[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned char k3[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,                         	0x00};
unsigned char c3[8] = {0xA1, 0x12, 0xFF, 0xC7, 0x2F, 0x68, 0x41, 0x7B};

unsigned char p4[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned char k4[10] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                        0xFF};
unsigned char c4[8] = {0x33, 0x33, 0xDC, 0xD3, 0x21, 0x32, 0x10, 0xD2};

//
// Testing begins
//
int main() {
	cout << "randomInverseTransform Tests" << endl;
	cout << "============================" << endl;

	cout << "* sBoxLayer...";
	if(randomInverseTransform(sBoxLayer, inv_sBoxLayer, 1000) != 0)
		cout << "FAILED" << endl;
	else
		cout << "passed" << endl;

	cout << "* pLayer...";
	if(randomInverseTransform(pLayer, inv_pLayer, 1000) != 0)
		cout << "FAILED" << endl;
	else
		cout << "passed" << endl;

	cout << endl;
	cout << "General Cipher Tests" << endl;
	cout << "====================" << endl;

	cout << "* autoInverseCipherTest...";
	if(autoInverseCipherTest(10) != 0)
		cout << "FAILED" << endl;
	else
		cout << "passed" << endl;

	cout << endl;
	cout << "Vector Tests" << endl;
	cout << "============" << endl;

	cout << "* 1...";
	if(vectorTestCase(p1, k1, c1) != 0)
		cout << "FAILED" << endl;
	else
		cout << "passed" << endl;

	cout << "* 2...";
	if(vectorTestCase(p2, k2, c2) != 0)
		cout << "FAILED" << endl;
	else
		cout << "passed" << endl;
	
	cout << "* 3...";
	if(vectorTestCase(p3, k3, c3) != 0)
		cout << "FAILED" << endl;
	else
		cout << "passed" << endl;

	cout << "* 4...";
	if(vectorTestCase(p4, k4, c4) != 0)
		cout << "FAILED" << endl;
	else
		cout << "passed" << endl;

	return 0;
}	
